package org.rkuk.kasutil.media 
{
	import org.rkuk.kasutil.designPatternTools.AbstractTool;
	/**
	 * 能够保留征听上一个状态中还未完成的seek操作或将Seek传入下一个状态
	 * @author ...
	 */
	internal class SeekState extends MediaState 
	{
		protected var isSeeking:Boolean;
		
		public function SeekState(media:MediaProxy,isSeeking:Boolean) 
		{
			AbstractTool.makeAbstractClass(this, SeekState);
			super(media);
			this.isSeeking = isSeeking;
			if (isSeeking)
				media.addEventListener(MediaStreamStatusEvent.STATUS_SEEK, onMediaSeek);
		}
		
		/**
		 * 征听MediaProxy发出的跳至指定时间播放事件，切换状态并发出MediaSourceEvent
		 * @param	e	MediaProxy发出的跳至指定时间播放事件
		 */
		protected function onMediaSeek(e:MediaStreamStatusEvent):void 
		{
			media.removeEventListener(MediaStreamStatusEvent.STATUS_SEEK, onMediaSeek);
			isSeeking = false;
			media.sendMediaEvent(new MediaSourceEvent(MediaSourceEvent.SEEK));
		}
		
		override public function dispose():void 
		{
			if (media.hasEventListener(MediaStreamStatusEvent.STATUS_SEEK))
				media.removeEventListener(MediaStreamStatusEvent.STATUS_SEEK, onMediaSeek);
				
			super.dispose();
		}
	}

}